package kr.co.bettersoft.pushchat.common;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import kr.co.bettersoft.pushchat.activity.R;
import kr.co.bettersoft.pushchat.domain.ChatMember;
import kr.co.bettersoft.pushchat.domain.ChatMessage;
import kr.co.bettersoft.pushchat.domain.ChatRoom;
import kr.co.bettersoft.pushchat.domain.ImageFile;
import kr.co.bettersoft.pushchat.domain.PushChatBlock;
import kr.co.bettersoft.pushchat.domain.PushChatChat;
import kr.co.bettersoft.pushchat.domain.PushChatDiary;
import kr.co.bettersoft.pushchat.domain.PushChatFriend;
import kr.co.bettersoft.pushchat.domain.PushChatLog;
import kr.co.bettersoft.pushchat.domain.PushChatMember;
import kr.co.bettersoft.pushchat.domain.PushChatMessage;
import kr.co.bettersoft.pushchat.domain.PushChatRecognition;
import kr.co.bettersoft.pushchat.domain.PushChatRecommendation;
import kr.co.bettersoft.pushchat.domain.PushChatSMS;
import kr.co.bettersoft.pushchat.domain.PushChatUser;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

/**
 * PushChatRest
 * 서버와의 통신관련 메소드들을 모아놓은 클래스이다.
 * @author blue
 *
 */
public class PushChatRest {
	String TAG = "PushChatRest";

	// 서버 통신
	int responseCode = 0;
	String controllerName ="";
	String methodName ="";
	String serverName = CommonConstant.serverNames;

	int isRunning = 0;		// 통신 도중 중복 호출을 방지하기 위함.
	String fullUrl = "";
	String inputJson = "";

	JSONObject obj;
	JSONObject jsonObject;
	JSONArray jsonArray;

	String nowDate = "";

	//	Context context;

	// 결과
	//	String callResult = "";
	//	String tempstr = "";


	//	/*
	//	 *  전달받은 값
	//	 */
	//	ChatMember chatMember = new ChatMember();  
	//	// 생성한 채팅방 정보
	//	ChatRoom createdRoomInfo = new ChatRoom();
	//	// 전달받은 채팅 메시지정보
	//	ChatMessage chatMessage = new ChatMessage();
	//	// 채팅할 상대방 idx
	//	int chatWithUseridx = 0;
	//
	//	// 채팅 정보
	//	PushChatChat pushChatChat = new PushChatChat();
	//	// 다이어리 정보
	//	PushChatDiary pushChatDiary = new PushChatDiary();
	//	// 친구 정보
	//	PushChatFriend pushChatFriend = new PushChatFriend();
	//	// 로그 정보
	//	PushChatLog pushChatLog = new PushChatLog();
	//	// 채팅 멤버 정보
	//	PushChatMember pushChatMember = new PushChatMember();
	//	// 메시지 정보
	//	PushChatMessage pushChatMessage = new PushChatMessage();
	//	// 메시지 읽음 여부 정보
	//	PushChatRecognition pushChatRecognition = new PushChatRecognition();
	//	// 추천 정보
	//	PushChatRecommendation pushChatRecommendation = new PushChatRecommendation();
	//	// 인증 정보
	//	PushChatSMS pushChatSMS = new PushChatSMS();
	//	// 사용자 정보
	//	PushChatUser pushChatUser = new PushChatUser();
	//	// 이미지 파일
	//	ImageFile imageFile = new ImageFile();


	//	// 멤버 리스트
	//	public ArrayList<PushChatMember> pushChatMemberEntries = new ArrayList<PushChatMember>(); 
	//	List<PushChatMember> pushChatMemberEntriesFn = new ArrayList<PushChatMember>();
	//	// 친구 리스트
	//	public ArrayList<PushChatFriend> pushChatFriendEntries = new ArrayList<PushChatFriend>(); 
	//	List<PushChatFriend> pushChatFriendEntriesFn = new ArrayList<PushChatFriend>();
	//	// 채팅방 리스트
	//	public ArrayList<PushChatChat> pushChatChatEntries = new ArrayList<PushChatChat>(); 
	//	List<PushChatChat> pushChatChatEntriesFn = new ArrayList<PushChatChat>();
	//	// 채팅방 메시지 리스트
	//	public ArrayList<PushChatMessage> pushChatMessageEntries = new ArrayList<PushChatMessage>(); 
	//	List<PushChatMessage> pushChatMessageEntriesFn = new ArrayList<PushChatMessage>();
	//	// 다이어리 리스트
	//	public ArrayList<PushChatDiary> pushChatDiaryEntries = new ArrayList<PushChatDiary>(); 
	//	List<PushChatDiary> pushChatDiaryEntriesFn = new ArrayList<PushChatDiary>();


	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	// 서버 통신

	/* -- 인증 관련 -- */
	/**
	 * RestRequestCertification
	 *  휴대폰번호로 인증번호를 요청한다.
	 */
	public String RestRequestCertification(PushChatSMS pushChatSMSParam){
		//		pushChatSMS = pushChatSMSParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		Log.d(TAG,"nowDate:"+nowDate);

		// 파라미터 셋팅
		controllerName = "pushChatCertificationController";
		methodName = "requestCertification";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("phoneNumber", pushChatSMSParam.getPhoneNumber()); // 전번
			obj.put("modifyDate", nowDate);
			obj.put("registerDate", nowDate); 
			obj.put("activateYn", "Y"); // 활성화 여부 -> 무조건 Y
		}catch(Exception e){
			Log.d(TAG,"RestRequestCertification");
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);
			try {
				jsonObject = new JSONObject(callResult);		// result
				callResult = "";
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		return callResult;
	}

	/**
	 * RestRequestAdmission
	 *  휴대폰번호,인증번호로 인증을 받는다
	 */
	public String RestRequestAdmission(PushChatSMS pushChatSMSParam){

		//		pushChatSMS = pushChatSMSParam;

		// 파라미터 셋팅
		controllerName = "pushChatCertificationController";
		methodName = "requestAdmission";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("phoneNumber", pushChatSMSParam.getPhoneNumber()); // 전번
			obj.put("certificationNumber", pushChatSMSParam.getCertificationNumber());
			obj.put("activateYn", "Y"); // 활성화 여부 -> 무조건 Y
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);
			try {
				jsonObject = new JSONObject(callResult);		// result
				callResult = "";
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		return callResult;
	}



	/* -- 채팅방 관련 -- */
	/**
	 * RestRegisterChatAndRegisterUser
	 * 채팅방을 생성하고 사용자를 등록 한다.
	 */
	public String RestRegisterChatAndRegisterUser(PushChatChat pushChatChatParam){

		//		pushChatChat = pushChatChatParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatChatController";
		methodName = "registerChatAndRegisterUser";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("owner", pushChatChatParam.getOwner()); 
			obj.put("ip", pushChatChatParam.getIp()); 
			obj.put("activateYn", "Y"); // 활성화 여부 -> 무조건 Y
			obj.put("modifyDate", nowDate); 
			obj.put("registerDate", nowDate); 
			obj.put("memberId", pushChatChatParam.getMemberId()); 
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		//		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//			callResult = tempstr;
		//		}
		return callResult;
	}
	/**
	 * RestSelectChatInformation
	 *  채팅방 정보를 가져 온다.		(채팅방을 생성할때 호출한다.)
	 */
	public String RestSelectChatInformation(PushChatChat pushChatChatParam){

		//		pushChatChat = pushChatChatParam;
		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatChatController";
		methodName = "selectChatInformation";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("owner", pushChatChatParam.getOwner()); 
			obj.put("activateYn", "Y"); // 활성화 여부 -> 무조건 Y
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		////			callResult = tempstr;
		//			//			Log.d(TAG,"RestSelectChatInformation//tempstr:"+tempstr);
		//			//			{"idChat":"88",
		//			//				"owner":"test01",
		////			try {
		////				jsonObject = new JSONObject(tempstr);
		////				pushChatChat.setIdChat(jsonObject.getString("idChat").toString());
		////				pushChatChat.setOwner(jsonObject.getString("owner").toString());
		////			} catch (Exception e) {
		////				callResult = "F";
		////				e.printStackTrace();
		////			}
		//		}
		return callResult;
	}

	/**
	 * RestSelectChatList
	 * 채팅방 목록을 가져 온다.
	 */
	public String RestSelectChatList(PushChatChat pushChatChatParam, Context contextParam){

		//		pushChatChat = pushChatChatParam;

		// 파라미터 셋팅
		controllerName = "pushChatChatController";
		methodName = "selectChatList";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatChatParam.getMemberId()); 
			obj.put("activateYn", "Y"); // 활성화 여부 -> 무조건 Y
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//			callResult = tempstr;
		//		}
		return callResult;
	}
	/**
	 * RestUpdateDeactivateUser
	 * 채팅방 사용자 비활성화 - > 사용자 화면에서의 채팅방 삭제
	 */
	public String RestUpdateDeactivateUser(PushChatUser pushChatUserParam){

		//		pushChatUser = pushChatUserParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatUserController";
		methodName = "updateDeactivateUser";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();

		try{		 
			obj.put("memberId", pushChatUserParam.getMemberId()); 
			obj.put("activateYn", "N"); 								// 활성화 여부 
			obj.put("modifyDate", nowDate); 
			obj.put("pushChatChatIdChat", pushChatUserParam.getPushChatChatIdChat()); 
			obj.put("pushChatChatOwner", pushChatUserParam.getPushChatChatOwner()); 
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);
				callResult = jsonObject.getString("result").toString(); 
			} catch (Exception e) {
				callResult = "F";
				e.printStackTrace();
			}
		}
		return callResult;
	}


	/* -- 다이어리 관련 -- */	
	/**
	 * RestRegisterDiary
	 * 일기를 등록 한다.
	 */
	public String RestRegisterDiary(PushChatDiary pushChatDiaryParam){

		//		pushChatDiary = pushChatDiaryParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatDiaryController";
		methodName = "registerDiary";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatDiaryParam.getMemberId()); 
			obj.put("category", pushChatDiaryParam.getCategory()); 
			obj.put("subject", pushChatDiaryParam.getSubject()); 
			obj.put("content", pushChatDiaryParam.getContent()); 
			obj.put("fileUrl", pushChatDiaryParam.getFileUrl()); 
			obj.put("activateYn", "Y"); 
			obj.put("modifyDate", nowDate); 
			obj.put("registerDate", nowDate); 
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log. d(TAG,"tempstr:"+tempstr);		
			try {
				jsonObject = new JSONObject(callResult);
				callResult = jsonObject.getString("result").toString(); 
			} catch (Exception e) {
				callResult = "F";
				e.printStackTrace();
			}
		}
		return callResult;
	}

	/**
	 * RestRegisterDiaryWithImage
	 * 일기와 이미지를 같이 등록 한다.
	 */
	public String RestRegisterDiaryWithImage(PushChatDiary pushChatDiaryParam, Context context)  throws ClientProtocolException, IOException {

		//		pushChatDiary = pushChatDiaryParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatDiaryController";
		methodName = "registerDiaryWithImage";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;

		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httppost ;
		MultipartEntity mpEntity ;
		HttpResponse response = null;
		HttpEntity resEntity = null ;
		try {
			httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
			httppost = new HttpPost(fullUrl);
			mpEntity = new MultipartEntity();
			//차후 수정 서버 부분 수정
			mpEntity.addPart("memberId", new StringBody(pushChatDiaryParam.getMemberId()));
			mpEntity.addPart("category", new StringBody(pushChatDiaryParam.getCategory()));
			mpEntity.addPart("subject", new StringBody(pushChatDiaryParam.getSubject()));
			mpEntity.addPart("content", new StringBody(pushChatDiaryParam.getContent()));
			mpEntity.addPart("fileUrl", new StringBody(pushChatDiaryParam.getFileUrl()));
			mpEntity.addPart("activateYn", new StringBody("Y"));
			mpEntity.addPart("modifyDate", new StringBody(nowDate));
			mpEntity.addPart("registerDate", new StringBody(nowDate));

			// 이미지가 있으면 이미지를 보냄
			Bitmap selectedImg = pushChatDiaryParam.getFile();

			//Convert bitmap to byte array
			ByteArrayOutputStream bos = new ByteArrayOutputStream();		// ByteArrayOutputStream 객체 bos 생성
			selectedImg.compress(Bitmap.CompressFormat.PNG, 0, bos);		// 이미지를 PNG로 변환하여 bos 에 저장
			byte[] data = bos.toByteArray();								// 이미지를 byte[] 형으로 꺼냄
			Log.d(TAG,"img size3:"+data.length);							// 파일 용량

			String fileName = pushChatDiaryParam.getMemberId() + "_" + commonUtil.getNowDateForImage() + ".png";		// 이미지 이름 설정
			Log.d(TAG,"fileName::"+fileName);
			mpEntity.addPart("fileName", new StringBody(fileName));

			File file = new File(context.getCacheDir(), fileName);
			file.createNewFile();

			//write the bytes in file
			FileOutputStream fos = new FileOutputStream(file);
			fos.write(data);
			fos.flush();
			fos.close();

			// 이부분의 설정으로 파일을 보낸다.
			ContentBody cbFile = new FileBody(file, "image/jpeg");
			mpEntity.addPart("file", cbFile);  //서버에서 처리해주는 파일이름이 file 이 되겠고, 내가 보내는 파일이 cbFile이다.	
			// 문서상에는 imageData 라고 되어있는데 실제로는 순번 가맹점 이벤트 등록때처럼 file 이었음.
			//			mpEntity.addPart("imageData", cbFile);  //서버에서 처리해주는 파일이름이 imageData 이 되겠고, 내가 보내는 파일이 cbFile이다.
			//			}
			httppost.setEntity(mpEntity);
			response = httpclient.execute(httppost);
			resEntity = response.getEntity();
			httpclient.getConnectionManager().shutdown();
		} catch (Exception e) {
			e.printStackTrace();
		}
		String callResult;
		if (resEntity != null) {
			String tmpStr = EntityUtils.toString(resEntity);
			Log.d(TAG,"tmpStr:"+tmpStr);
			try {
				jsonObject = new JSONObject(tmpStr);
				callResult = jsonObject.getString("result").toString(); 
			} catch (Exception e) {
				callResult = "F";
				e.printStackTrace();
			}
		}else{
			callResult = "F";
		}

		//		obj = new JSONObject();
		//		try{		 
		//			obj.put("memberId", pushChatDiary.getMemberId()); 
		//			obj.put("category", pushChatDiary.getCategory()); 
		//			obj.put("subject", pushChatDiary.getSubject()); 
		//			obj.put("content", pushChatDiary.getContent()); 
		//			obj.put("fileUrl", pushChatDiary.getFileUrl()); 
		//			obj.put("activateYn", "Y"); 
		//			obj.put("modifyDate", nowDate); 
		//			obj.put("registerDate", nowDate); 
		//			obj.put("fileName", imageFile.getFileName()); 		
		//			obj.put("imageData", imageFile.getImageData()); 
		//		}catch(Exception e){
		//			e.printStackTrace();
		//		}
		//		inputJson = obj.toString();
		//
		//		// 서버호출 메소드 실행
		//		callResult = callServerMethod(fullUrl, inputJson);
		//
		//		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//			Log.d(TAG,"tempstr:"+tempstr);
		//		}
		return callResult;
	}

	/**
	 * RestUpdateDiary
	 * 일기를 수정 한다.
	 */
	public String RestUpdateDiary(PushChatDiary pushChatDiaryParam){

		//		pushChatDiary = pushChatDiaryParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatDiaryController";
		methodName = "updateDiary";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("idPushChatDiary", pushChatDiaryParam.getIdPushChatDiary()); 
			obj.put("memberId", pushChatDiaryParam.getMemberId()); 
			obj.put("category", pushChatDiaryParam.getCategory()); 
			obj.put("subject", pushChatDiaryParam.getSubject()); 
			obj.put("content", pushChatDiaryParam.getContent()); 
			obj.put("fileUrl", pushChatDiaryParam.getFileUrl()); 
			obj.put("activateYn", "Y"); 
			obj.put("modifyDate", nowDate); 
			//			obj.put("registerDate", nowDate); 
			//			obj.put("fileName", pushChatDiary.getFileName()); 
			//			obj.put("imageData", pushChatDiary.getImageData());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		//		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//		}
		return callResult;
	}

	/**
	 * RestUpdateDiaryWithImage
	 * 일기와 이미지를 같이 수정 한다.
	 */
	public String RestUpdateDiaryWithImage(PushChatDiary pushChatDiaryParam, ImageFile imageFileParam){

		//		pushChatDiary = pushChatDiaryParam;
		//		imageFile = imageFileParam;
		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatDiaryController";
		methodName = "updateDiaryWithImage";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("idPushChatDiary", pushChatDiaryParam.getIdPushChatDiary()); 
			obj.put("memberId", pushChatDiaryParam.getMemberId()); 
			obj.put("category", pushChatDiaryParam.getCategory()); 
			obj.put("subject", pushChatDiaryParam.getSubject()); 
			obj.put("content", pushChatDiaryParam.getContent()); 
			obj.put("fileUrl", pushChatDiaryParam.getFileUrl()); 
			obj.put("activateYn", "Y"); 
			obj.put("modifyDate", nowDate); 
			//			obj.put("registerDate", nowDate); 
			obj.put("fileName", imageFileParam.getFileName()); 		
			obj.put("imageData", imageFileParam.getImageData()); 
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		//		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//		}
		return callResult;
	}

	/**
	 * RestUpdateDeactivateDiary
	 * 일기를 비활성화 한다.
	 */
	public String RestUpdateDeactivateDiary(PushChatDiary pushChatDiaryParam){

		//		pushChatDiary = pushChatDiaryParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatDiaryController";
		methodName = "updateDeactivateDiary";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("idPushChatDiary", pushChatDiaryParam.getIdPushChatDiary()); 
			obj.put("memberId", pushChatDiaryParam.getMemberId()); 
			obj.put("activateYn", "N"); 
			obj.put("modifyDate", nowDate); 
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);
				callResult = jsonObject.getString("result").toString(); 
			} catch (Exception e) {
				callResult = "F";
				e.printStackTrace();
			}
		}
		return callResult;
	}

	/**
	 * RestSelectDiaryInformation
	 * 일기 상세 정보를 가져 온다.
	 */
	public String RestSelectDiaryInformation(PushChatDiary pushChatDiaryParam, Context contextParam){

		//		pushChatDiary = pushChatDiaryParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatDiaryController";
		methodName = "selectDiaryInformation";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("idPushChatDiary", pushChatDiaryParam.getIdPushChatDiary()); 
			//			obj.put("memberId", pushChatDiary.getMemberId()); 
			//			obj.put("category", pushChatDiary.getCategory()); 
			//			obj.put("subject", pushChatDiary.getSubject()); 
			//			obj.put("content", pushChatDiary.getContent()); 
			//			obj.put("fileUrl", pushChatDiary.getFileUrl()); 
			obj.put("activateYn", "Y"); 
			//			obj.put("modifyDate", nowDate); 
			//			obj.put("registerDate", nowDate); 
			//			obj.put("fileName", pushChatDiary.getFileName()); 
			//			obj.put("imageData", pushChatDiary.getImageData());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		//		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//			callResult = tempstr;
		//		}
		return callResult;
	}

	/**
	 * RestSelectMyDiaryList
	 * 내 일기 목록을 가져 온다.
	 */
	public String RestSelectMyDiaryList(PushChatDiary pushChatDiaryParam, Context contextParam){

		//		pushChatDiary = pushChatDiaryParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatDiaryController";
		methodName = "selectMyDiaryList";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			//			obj.put("idPushChatDiary", pushChatDiary.getIdPushChatDiary()); 
			obj.put("memberId", pushChatDiaryParam.getMemberId()); 
			//			obj.put("category", pushChatDiary.getCategory()); 
			//			obj.put("subject", pushChatDiary.getSubject()); 
			//			obj.put("content", pushChatDiary.getContent()); 
			//			obj.put("fileUrl", pushChatDiary.getFileUrl()); 
			obj.put("activateYn", "Y"); 
			//			obj.put("modifyDate", nowDate); 
			//			obj.put("registerDate", nowDate); 
			//			obj.put("fileName", pushChatDiary.getFileName()); 
			//			obj.put("imageData", pushChatDiary.getImageData());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		//		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//			callResult = tempstr;
		//		}
		return callResult;
	}

	/**
	 * RestSelectSearchDiaryList
	 * 검색한 일기 목록을 가져 온다.
	 */
	public String RestSelectSearchDiaryList(PushChatDiary pushChatDiaryParam, Context contextParam){

		//		pushChatDiary = pushChatDiaryParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatDiaryController";
		methodName = "selectSearchDiaryList";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			//			obj.put("idPushChatDiary", pushChatDiary.getIdPushChatDiary()); 
			//			obj.put("memberId", pushChatDiary.getMemberId()); 
			obj.put("nickName", pushChatDiaryParam.getNickName()); 
			obj.put("category", pushChatDiaryParam.getCategory()); 
			obj.put("subject", pushChatDiaryParam.getSubject()); 
			obj.put("content", pushChatDiaryParam.getContent()); 
			//			obj.put("fileUrl", pushChatDiary.getFileUrl()); 
			obj.put("activateYn", "Y"); 
			//			obj.put("modifyDate", nowDate); 
			//			obj.put("registerDate", nowDate); 
			//			obj.put("fileName", pushChatDiary.getFileName()); 
			//			obj.put("imageData", pushChatDiary.getImageData());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		//		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//			callResult = tempstr;
		//		}
		return callResult;
	}


	/* -- 친구 관련 -- */	
	/**
	 * RestSelectDuplicationFriend
	 * 친구 등록전 중복 검사를 한다.
	 */
	public String RestSelectDuplicationFriend(PushChatFriend pushChatFriendParam){

		//		pushChatFriend = pushChatFriendParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatFriendController";
		methodName = "selectDuplicationFriend";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatFriendParam.getMemberId()); 
			obj.put("activateYn", "Y"); 
			obj.put("pushChatMemberMemberId", pushChatFriendParam.getPushChatMemberMemberId()); 
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// totalCount
				callResult = "";
				try{
					callResult = jsonObject.getString("totalCount");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}else{
			callResult = "F";
		}
		return callResult;
	}

	/**
	 * RestRegisterFriend
	 * 친구를 등록 한다.
	 */
	public String RestRegisterFriend(PushChatFriend pushChatFriendParam){

		//		pushChatFriend = pushChatFriendParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatFriendController";
		methodName = "registerFriend";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatFriendParam.getMemberId()); 
			obj.put("category", pushChatFriendParam.getCategory()); 
			obj.put("activateYn", "Y"); 
			obj.put("modifyDate", nowDate); 
			obj.put("registerDate", nowDate); 
			obj.put("pushChatMemberMemberId", pushChatFriendParam.getPushChatMemberMemberId()); 
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// result
				callResult = "";
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		return callResult;
	}

	/**
	 * RestUpdateDeactivateFriend
	 * 친구를 비활성화 한다.
	 */
	public String RestUpdateDeactivateFriend(PushChatFriend pushChatFriendParam){

		//		pushChatFriend = pushChatFriendParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatFriendController";
		methodName = "updateDeactivateFriend";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatFriendParam.getMemberId()); 
			obj.put("activateYn", "N"); 		// 친구 비활성때는 N
			obj.put("modifyDate", nowDate); 
			obj.put("pushChatMemberMemberId", pushChatFriendParam.getPushChatMemberMemberId()); 
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// result
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		return callResult;
	}

	/**
	 * RestSelectFriendList
	 * 친구 목록을 가져 온다.
	 */
	public String RestSelectFriendList(PushChatFriend pushChatFriendParam){

		//		pushChatFriend = pushChatFriendParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatFriendController";
		methodName = "selectFriendList";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("activateYn", "Y"); 
			obj.put("pushChatMemberMemberId", pushChatFriendParam.getPushChatMemberMemberId()); 
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);
		//
		//		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//			callResult = tempstr;
		//		}
		return callResult;
	}


	/* -- 로그  관련 -- */
	/**
	 * RestRegisterLog
	 * 로그를 등록 한다.
	 */
	public String RestRegisterLog(PushChatLog pushChatLogParam){

		//		pushChatLog = pushChatLogParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatLogController";
		methodName = "registerLog";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("idChat", pushChatLogParam.getIdChat());
			obj.put("memberId", pushChatLogParam.getMemberId());
			obj.put("content", pushChatLogParam.getContent());
			obj.put("registerDate", nowDate);
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);
			//			try {
			//				jsonObject = new JSONObject(tempstr);		// 
			//				callResult = "";
			//				try{
			//					callResult = jsonObject.getString("totalCount");
			//				}catch(Exception e){
			//					callResult = "0";
			//				}
			//			} catch (JSONException e) {
			//				callResult = "0";
			//			}
		}
		return callResult;
	}


	/* -- 멤버(사용자) 관련 -- */

	/**
	 * RestSelectDuplicationMember
	 * 멤버 등록시 중복 검사를 한다.
	 */
	public String RestSelectDuplicationMember(PushChatMember pushChatMemberParam){

		//		pushChatMember = pushChatMemberParam;



		// 파라미터 셋팅
		controllerName = "pushChatMemberController";
		methodName = "selectDuplicationMember";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatMemberParam.getMemberId());
			obj.put("activateYn", "Y");
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// 
				callResult = "";
				try{
					callResult = jsonObject.getString("totalCount");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}else{
			callResult = "F";
		}
		return callResult;
	}

	/**
	 * RestRegisterMember
	 * 멤버를 등록 한다.
	 */
	public String RestRegisterMember(PushChatMember pushChatMemberParam){

		//		pushChatMember = pushChatMemberParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatMemberController";
		methodName = "registerMember";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatMemberParam.getMemberId());
			obj.put("password", pushChatMemberParam.getPassword());
			obj.put("nickName", pushChatMemberParam.getNickName());
			obj.put("phoneNumber", pushChatMemberParam.getPhoneNumber());
			obj.put("email", pushChatMemberParam.getEmail());
			obj.put("comment", pushChatMemberParam.getComment());
			obj.put("profileImageUrl", pushChatMemberParam.getProfileImageUrl());
			//			obj.put("thumbnailUrl", pushChatMember.getThumbnailUrl());
			Log.d(TAG,"thumbnailUrl:"+pushChatMemberParam.getThumbnailUrl());
			obj.put("thumbnailUrl", "");
			obj.put("gender", pushChatMemberParam.getGender());
			obj.put("age", pushChatMemberParam.getAge());
			obj.put("countryCode", pushChatMemberParam.getCountryCode());
			obj.put("languageCode", pushChatMemberParam.getLanguageCode());
			obj.put("latitude", pushChatMemberParam.getLatitude());
			obj.put("longitude", pushChatMemberParam.getLongitude());
			obj.put("location", pushChatMemberParam.getLocation());
			obj.put("openLocationYn", pushChatMemberParam.getOpenLocationYn());
			obj.put("personalityType", pushChatMemberParam.getPersonalityType());
			obj.put("deviceType", pushChatMemberParam.getDeviceType());
			obj.put("registrationId", pushChatMemberParam.getRegistrationId());
			obj.put("receiveNotificationYn", pushChatMemberParam.getReceiveNotificationYn());
			obj.put("restrictionYn", pushChatMemberParam.getRestrictionYn());
			obj.put("activateYn", "Y");
			obj.put("modifyDate", nowDate);
			obj.put("registerDate", nowDate);
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// result SUCCESS
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		return callResult;
	}

	/**
	 * RestLogin
	 * 로그인을 한다.
	 */
	public String RestLogin(PushChatMember pushChatMemberParam){

		//		pushChatMember = pushChatMemberParam;
		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatMemberController";
		methodName = "login";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatMemberParam.getMemberId());
			obj.put("password", pushChatMemberParam.getPassword());
			//			obj.put("nickName", pushChatMember.getNickName());
			//			obj.put("phoneNumber", pushChatMember.getPhoneNumber());
			//			obj.put("email", pushChatMember.getEmail());
			//			obj.put("comment", pushChatMember.getComment());
			//			obj.put("profileImageUrl", pushChatMember.getProfileImageUrl());
			//			obj.put("gender", pushChatMember.getGender());
			//			obj.put("age", pushChatMember.getAge());
			//			obj.put("countryCode", pushChatMember.getCountryCode());
			//			obj.put("languageCode", pushChatMember.getLanguageCode());
			//			obj.put("latitude", pushChatMember.getLatitude());
			//			obj.put("longitude", pushChatMember.getLongitude());
			//			obj.put("location", pushChatMember.getLocation());
			//			obj.put("openLocationYn", pushChatMember.getOpenLocationYn());
			//			obj.put("personalityType", pushChatMember.getPersonalityType());
			//			obj.put("deviceType", pushChatMember.getDeviceType());
			//			obj.put("registrationId", pushChatMember.getRegistrationId());
			//			obj.put("receiveNotificationYn", pushChatMember.getReceiveNotificationYn());
			obj.put("restrictionYn", "Y");
			obj.put("activateYn", "Y");
			//			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// totalCount
				try{
					callResult = jsonObject.getString("totalCount");
				}catch(Exception e){
					callResult = "0";
				}
			} catch (JSONException e) {
				callResult = "0";
			}
		}else{
			callResult = "0";
		}
		return callResult;
	}

	//	/**
	//	 * RestSelectMemberList
	//	 * 전체 멤버 목록을 가져 온다.
	//	 */
	//	public String RestSelectMemberList(){	// PushChatMember pushChatMemberParam
	//
	//		//		pushChatMember = pushChatMemberParam;
	//
	//		CommonUtil commonUtil = new CommonUtil();
	//		nowDate = commonUtil.getNowDate();
	//
	//		// 파라미터 셋팅
	//		controllerName = "pushChatMemberController";
	//		methodName = "selectMemberList";
	//		fullUrl = serverName+"/"+controllerName+"/"+methodName;
	//		obj = new JSONObject();
	//		try{		 
	//			//			obj.put("memberId", pushChatMember.getMemberId());
	//			//			obj.put("password", pushChatMember.getPassword());
	//			//			obj.put("nickName", pushChatMember.getNickName());
	//			//			obj.put("phoneNumber", pushChatMember.getPhoneNumber());
	//			//			obj.put("email", pushChatMember.getEmail());
	//			//			obj.put("comment", pushChatMember.getComment());
	//			//			obj.put("profileImageUrl", pushChatMember.getProfileImageUrl());
	//			//			obj.put("gender", pushChatMember.getGender());
	//			//			obj.put("age", pushChatMember.getAge());
	//			//			obj.put("countryCode", pushChatMember.getCountryCode());
	//			//			obj.put("languageCode", pushChatMember.getLanguageCode());
	//			//			obj.put("latitude", pushChatMember.getLatitude());
	//			//			obj.put("longitude", pushChatMember.getLongitude());
	//			//			obj.put("location", pushChatMember.getLocation());
	//			//			obj.put("openLocationYn", pushChatMember.getOpenLocationYn());
	//			//			obj.put("personalityType", pushChatMember.getPersonalityType());
	//			//			obj.put("deviceType", pushChatMember.getDeviceType());
	//			//			obj.put("registrationId", pushChatMember.getRegistrationId());
	//			//			obj.put("receiveNotificationYn", pushChatMember.getReceiveNotificationYn());
	//			obj.put("activateYn", "Y");
	//			//			obj.put("modifyDate", nowDate);
	//			//			obj.put("registerDate", nowDate);
	//		}catch(Exception e){
	//			e.printStackTrace();
	//		}
	//		inputJson = obj.toString();
	//
	//		// 서버호출 메소드 실행
	//		callResult = callServerMethod(fullUrl, inputJson);
	//
	//		// 서버 호출 결과 처리
	//		if(!(callResult.equals("F"))){
	//			try {
	//				jsonArray = new JSONArray(tempstr);
	//			} catch (JSONException e1) {
	//				e1.printStackTrace();
	//			}
	//			int max = jsonArray.length();
	//			try {
	//				pushChatMemberEntries = new ArrayList<PushChatMember>(max);
	//
	//				String tmp_memberId = "";
	//				String tmp_nickName = "";
	//				String tmp_phoneNumber = "";
	//				String tmp_email = "";
	//				String tmp_comment = "";
	//				String tmp_profileImageUrl = "";
	//				String tmp_thumbnailUrl = "";
	//				String tmp_gender = "";
	//				String tmp_age = "";
	//				String tmp_countryCode = "";
	//				String tmp_languageCode = "";
	//				String tmp_modifyDate = "";
	//				String tmp_registerDate = "";
	//				Bitmap tmp_profileImage = null;
	//				Bitmap tmp_thumbnail = null;
	//				////				chatRoomEntries1 = new ArrayList<ChatRoom>(max);
	//				//				String tmp_idChat = "";
	//				//				String tmp_owner = "";
	//				//				String tmp_modifyDate = "";
	//				//				String tmp_registerDate = "";
	//				if(max>0){
	//					for ( int i = 0; i < max; i++ ){
	//						JSONObject jsonObj = jsonArray.getJSONObject(i);
	//						try{
	//							tmp_memberId = jsonObj.getString("memberId");
	//						}catch(Exception e){
	//							tmp_memberId = "";
	//						}
	//						try{
	//							tmp_nickName = jsonObj.getString("nickName");
	//						}catch(Exception e){
	//							tmp_nickName = "";
	//						}
	//						try{
	//							tmp_phoneNumber = jsonObj.getString("phoneNumber");
	//						}catch(Exception e){
	//							tmp_phoneNumber = "";
	//						}
	//						try{
	//							tmp_email = jsonObj.getString("email");
	//						}catch(Exception e){
	//							tmp_email = "";
	//						}
	//						try{
	//							tmp_comment = jsonObj.getString("comment");
	//						}catch(Exception e){
	//							tmp_comment = "";
	//						}
	//						try{
	//							tmp_profileImageUrl = jsonObj.getString("profileImageUrl");
	//							if(tmp_profileImageUrl!=null&&tmp_profileImageUrl.length()>0){
	//								//								tmp_profileImage = LoadImage(tmp_profileImageUrl);
	//							}else{
	//								tmp_profileImage = null;
	//							}
	//						}catch(Exception e){
	//							tmp_profileImageUrl = "";
	//						}
	//						try{
	//							tmp_thumbnailUrl = jsonObj.getString("thumbnailUrl");
	//							if(tmp_thumbnailUrl!=null&&tmp_thumbnailUrl.length()>0){
	//								tmp_thumbnail = LoadImage(tmp_thumbnailUrl);
	//							}else{
	//								tmp_thumbnail = null;
	//							}
	//						}catch(Exception e){
	//							tmp_thumbnailUrl = "";
	//						}
	//						try{
	//							tmp_gender = jsonObj.getString("gender");
	//						}catch(Exception e){
	//							tmp_gender = "";
	//						}
	//						try{
	//							tmp_age = jsonObj.getString("age");
	//						}catch(Exception e){
	//							tmp_age = "";
	//						}
	//						try{
	//							tmp_countryCode = jsonObj.getString("countryCode");
	//						}catch(Exception e){
	//							tmp_countryCode = "";
	//						}
	//						try{
	//							tmp_languageCode = jsonObj.getString("languageCode");
	//						}catch(Exception e){
	//							tmp_languageCode = "";
	//						}
	//						try{
	//							tmp_modifyDate = jsonObj.getString("modifyDate");
	//						}catch(Exception e){
	//							tmp_modifyDate = "";
	//						}
	//						try{
	//							tmp_registerDate = jsonObj.getString("registerDate");
	//						}catch(Exception e){
	//							tmp_registerDate = "";
	//						}
	//						pushChatMemberEntries.add(new PushChatMember(tmp_memberId,
	//								tmp_nickName,
	//								tmp_phoneNumber,
	//								tmp_email,
	//								tmp_comment,
	//								tmp_profileImageUrl,
	//								tmp_thumbnailUrl,
	//								tmp_gender,
	//								tmp_age,
	//								tmp_countryCode,
	//								tmp_languageCode,
	//								tmp_modifyDate,
	//								tmp_registerDate,
	//								tmp_profileImage,
	//								tmp_thumbnail
	//						));
	//					}
	//				}
	//			}catch (JSONException e) {
	//				e.printStackTrace();
	//			}
	//			pushChatMemberEntriesFn = pushChatMemberEntries; 
	//
	//
	//			//			try {
	//			//				jsonObject = new JSONObject(tempstr);		// list member
	//			//				callResult = "";
	//			//				try{
	//			//					callResult = jsonObject.getString("totalCount");
	//			//				}catch(Exception e){
	//			//					callResult = "0";
	//			//				}
	//			//			} catch (JSONException e) {
	//			//				callResult = "0";
	//			//			}
	//		}
	//		return callResult;
	//	}
	/**
	 * RestUpdateRegistrationId
	 * ASPN/GCM 아이디를 업데이트 한다.
	 */
	public String RestUpdateRegistrationId(PushChatMember pushChatMemberParam){

		//		pushChatMember = pushChatMemberParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatMemberController";
		methodName = "updateRegistrationId";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			// 파라미터 없음? ### @@@ !!! 
			obj.put("memberId", pushChatMemberParam.getMemberId());	
			obj.put("activateYn", "Y");
			obj.put("registrationId", pushChatMemberParam.getRegistrationId());							
			obj.put("modifyDate", nowDate);							
			obj.put("deviceType", "AS");	
			//			obj.put("memberId", pushChatMember.getMemberId());
			//			obj.put("password", pushChatMember.getPassword());
			//			obj.put("nickName", pushChatMember.getNickName());
			//			obj.put("phoneNumber", pushChatMember.getPhoneNumber());
			//			obj.put("email", pushChatMember.getEmail());
			//			obj.put("comment", pushChatMember.getComment());
			//			obj.put("profileImageUrl", pushChatMember.getProfileImageUrl());
			//			obj.put("gender", pushChatMember.getGender());
			//			obj.put("age", pushChatMember.getAge());
			//			obj.put("countryCode", pushChatMember.getCountryCode());
			//			obj.put("languageCode", pushChatMember.getLanguageCode());
			//			obj.put("latitude", pushChatMember.getLatitude());
			//			obj.put("longitude", pushChatMember.getLongitude());
			//			obj.put("location", pushChatMember.getLocation());
			//			obj.put("openLocationYn", pushChatMember.getOpenLocationYn());
			//			obj.put("personalityType", pushChatMember.getPersonalityType());
			//			obj.put("deviceType", pushChatMember.getDeviceType());
			//			obj.put("registrationId", pushChatMember.getRegistrationId());
			//			obj.put("receiveNotificationYn", pushChatMember.getReceiveNotificationYn());
			//			obj.put("activateYn", "Y");
			//			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// 
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		return callResult;
	}
	/**
	 * RestSelectMemberInformation
	 * 멤버 상세 정보를 가져 온다.
	 */
	public String RestSelectMemberInformation(PushChatMember pushChatMemberParam, Context contextParam){

		//		pushChatMember = pushChatMemberParam;

		// 파라미터 셋팅
		controllerName = "pushChatMemberController";
		methodName = "selectMemberInformation";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatMemberParam.getMemberId());
			//			obj.put("password", pushChatMember.getPassword());
			//			obj.put("nickName", pushChatMember.getNickName());
			//			obj.put("phoneNumber", pushChatMember.getPhoneNumber());
			//			obj.put("email", pushChatMember.getEmail());
			//			obj.put("comment", pushChatMember.getComment());
			//			obj.put("profileImageUrl", pushChatMember.getProfileImageUrl());
			//			obj.put("gender", pushChatMember.getGender());
			//			obj.put("age", pushChatMember.getAge());
			//			obj.put("countryCode", pushChatMember.getCountryCode());
			//			obj.put("languageCode", pushChatMember.getLanguageCode());
			//			obj.put("latitude", pushChatMember.getLatitude());
			//			obj.put("longitude", pushChatMember.getLongitude());
			//			obj.put("location", pushChatMember.getLocation());
			//			obj.put("openLocationYn", pushChatMember.getOpenLocationYn());
			//			obj.put("personalityType", pushChatMember.getPersonalityType());
			//			obj.put("deviceType", pushChatMember.getDeviceType());
			//			obj.put("registrationId", pushChatMember.getRegistrationId());
			//			obj.put("receiveNotificationYn", pushChatMember.getReceiveNotificationYn());
			obj.put("activateYn", "Y");
			//			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		//		// 서버 호출 결과 처리
		//		if(!(callResult.equals("F"))){
		//			callResult = tempstr;
		//		}
		return callResult;
	}
	/**
	 * RestSelectSearchMemberList
	 * 검색한 멤버 목록을 가져 온다.
	 */
	public String RestSelectSearchMemberList(PushChatMember pushChatMemberParam){

		//		pushChatMember = pushChatMemberParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();
		// 파라미터 셋팅
		controllerName = "pushChatMemberController";
		methodName = "selectSearchMemberList";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatMemberParam.getMemberId());
			obj.put("nickName", pushChatMemberParam.getNickName());
			obj.put("gender", pushChatMemberParam.getGender());
			obj.put("age", pushChatMemberParam.getAge());
			obj.put("personalityType", pushChatMemberParam.getPersonalityType());
			obj.put("activateYn", "Y");
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			callResult = tempstr;

			//			try {
			//				jsonArray = new JSONArray(tempstr);
			//			} catch (JSONException e1) {
			//				e1.printStackTrace();
			//			}
			//			int max = jsonArray.length();
			//			try {
			//				pushChatMemberEntries = new ArrayList<PushChatMember>(max);
			//
			//				String tmp_memberId = "";
			//				String tmp_nickName = "";
			//				String tmp_phoneNumber = "";
			//				String tmp_email = "";
			//				String tmp_comment = "";
			//				String tmp_profileImageUrl = "";
			//				String tmp_thumbnailUrl = "";
			//				String tmp_gender = "";
			//				String tmp_age = "";
			//				String tmp_countryCode = "";
			//				String tmp_languageCode = "";
			//				String tmp_modifyDate = "";
			//				String tmp_registerDate = "";
			//				Bitmap tmp_profileImage = null;
			//				Bitmap tmp_thumbnail = null;
			//
			//				if(max>0){
			//					for ( int i = 0; i < max; i++ ){
			//						JSONObject jsonObj = jsonArray.getJSONObject(i);
			//						try{
			//							tmp_memberId = jsonObj.getString("memberId");
			//						}catch(Exception e){
			//							tmp_memberId = "";
			//						}
			//						try{
			//							tmp_nickName = jsonObj.getString("nickName");
			//						}catch(Exception e){
			//							tmp_nickName = "";
			//						}
			//						try{
			//							tmp_phoneNumber = jsonObj.getString("phoneNumber");
			//						}catch(Exception e){
			//							tmp_phoneNumber = "";
			//						}
			//						try{
			//							tmp_email = jsonObj.getString("email");
			//						}catch(Exception e){
			//							tmp_email = "";
			//						}
			//						try{
			//							tmp_comment = jsonObj.getString("comment");
			//						}catch(Exception e){
			//							tmp_comment = "";
			//						}
			//						try{
			//							tmp_profileImageUrl = jsonObj.getString("profileImageUrl");
			//							if(tmp_profileImageUrl!=null&&tmp_profileImageUrl.length()>0){
			//								//								tmp_profileImage = LoadImage(tmp_profileImageUrl);
			//							}else{
			//								tmp_profileImage = null;
			//							}
			//						}catch(Exception e){
			//							tmp_profileImageUrl = "";
			//						}
			//						try{
			//							tmp_thumbnailUrl = jsonObj.getString("thumbnailUrl");
			//							if(tmp_thumbnailUrl!=null&&tmp_thumbnailUrl.length()>0&&!(tmp_thumbnailUrl.equals("null"))){
			//								tmp_thumbnail = LoadImage(tmp_thumbnailUrl);
			//								tmp_thumbnail = commonUtil.getRoundedCornerBitmap(tmp_thumbnail); // 라운딩 처리
			//							}else{
			//								tmp_thumbnail = null;
			//							}
			//						}catch(Exception e){
			//							tmp_thumbnailUrl = "";
			//						}
			//						try{
			//							tmp_gender = jsonObj.getString("gender");
			//						}catch(Exception e){
			//							tmp_gender = "";
			//						}
			//						try{
			//							tmp_age = jsonObj.getString("age");
			//						}catch(Exception e){
			//							tmp_age = "";
			//						}
			//						try{
			//							tmp_countryCode = jsonObj.getString("countryCode");
			//						}catch(Exception e){
			//							tmp_countryCode = "";
			//						}
			//						try{
			//							tmp_languageCode = jsonObj.getString("languageCode");
			//						}catch(Exception e){
			//							tmp_languageCode = "";
			//						}
			//						try{
			//							tmp_modifyDate = jsonObj.getString("modifyDate");
			//						}catch(Exception e){
			//							tmp_modifyDate = "";
			//						}
			//						try{
			//							tmp_registerDate = jsonObj.getString("registerDate");
			//						}catch(Exception e){
			//							tmp_registerDate = "";
			//						}
			//						pushChatMemberEntries.add(new PushChatMember(tmp_memberId,
			//								tmp_nickName,
			//								tmp_phoneNumber,
			//								tmp_email,
			//								tmp_comment,
			//								tmp_profileImageUrl,
			//								tmp_thumbnailUrl,
			//								tmp_gender,
			//								tmp_age,
			//								tmp_countryCode,
			//								tmp_languageCode,
			//								tmp_modifyDate,
			//								tmp_registerDate,
			//								tmp_profileImage,
			//								tmp_thumbnail
			//						));
			//					}
			//				}
			//			}catch (JSONException e) {
			//				e.printStackTrace();
			//			}
			//			pushChatMemberEntriesFn = pushChatMemberEntries; 
		}
		return callResult;
	}
	/**
	 * RestUpdatePassword
	 * 비밀번호를 업데이트 한다.
	 */
	public String RestUpdatePassword(PushChatMember pushChatMemberParam){

		//		pushChatMember = pushChatMemberParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatMemberController";
		methodName = "updatePassword";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatMemberParam.getMemberId());
			obj.put("password", pushChatMemberParam.getPassword());
			//			obj.put("nickName", pushChatMember.getNickName());
			//			obj.put("phoneNumber", pushChatMember.getPhoneNumber());
			//			obj.put("email", pushChatMember.getEmail());
			//			obj.put("comment", pushChatMember.getComment());
			//			obj.put("profileImageUrl", pushChatMember.getProfileImageUrl());
			//			obj.put("gender", pushChatMember.getGender());
			//			obj.put("age", pushChatMember.getAge());
			//			obj.put("countryCode", pushChatMember.getCountryCode());
			//			obj.put("languageCode", pushChatMember.getLanguageCode());
			//			obj.put("latitude", pushChatMember.getLatitude());
			//			obj.put("longitude", pushChatMember.getLongitude());
			//			obj.put("location", pushChatMember.getLocation());
			//			obj.put("openLocationYn", pushChatMember.getOpenLocationYn());
			//			obj.put("personalityType", pushChatMember.getPersonalityType());
			//			obj.put("deviceType", pushChatMember.getDeviceType());
			//			obj.put("registrationId", pushChatMember.getRegistrationId());
			//			obj.put("receiveNotificationYn", pushChatMember.getReceiveNotificationYn());
			obj.put("activateYn", "Y");
			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// result
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}else{
			callResult = "F";
		}
		return callResult;
	}

	/**
	 * RestUpdateMemberInformation
	 * 멤버 상세 정보를 업데이트 한다.
	 */
	public String RestUpdateMemberInformation(PushChatMember pushChatMemberParam){

		//		pushChatMember = pushChatMemberParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatMemberController";
		methodName = "updateMemberInformation";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		 
			obj.put("memberId", pushChatMemberParam.getMemberId());
			//			obj.put("password", pushChatMember.getPassword());
			obj.put("nickName", pushChatMemberParam.getNickName());
			obj.put("phoneNumber", pushChatMemberParam.getPhoneNumber());
			obj.put("email", pushChatMemberParam.getEmail());
			obj.put("comment", pushChatMemberParam.getComment());
			obj.put("profileImageUrl", pushChatMemberParam.getProfileImageUrl());
			obj.put("thumbnailUrl", pushChatMemberParam.getThumbnailUrl());			// * 추가된 사항
			obj.put("gender", pushChatMemberParam.getGender());
			obj.put("age", pushChatMemberParam.getAge());
			obj.put("countryCode", pushChatMemberParam.getCountryCode());
			obj.put("languageCode", pushChatMemberParam.getLanguageCode());
			obj.put("latitude", pushChatMemberParam.getLatitude());
			obj.put("longitude", pushChatMemberParam.getLongitude());
			obj.put("location", pushChatMemberParam.getLocation());
			obj.put("openLocationYn", pushChatMemberParam.getOpenLocationYn());
			obj.put("personalityType", pushChatMemberParam.getPersonalityType());
			obj.put("deviceType", pushChatMemberParam.getDeviceType());
			obj.put("registrationId", pushChatMemberParam.getRegistrationId());
			obj.put("receiveNotificationYn", pushChatMemberParam.getReceiveNotificationYn());
			obj.put("activateYn", "Y");
			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// result
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}else{
			callResult = "F";
		}
		return callResult;
	}
	/**
	 * RestUpdateMemberInformationWithProfileImage
	 * 멤버 상세 정보와 프로필 이미지를 업데이트 한다.
	 */
	public String RestUpdateMemberInformationWithProfileImage(PushChatMember pushChatMemberParam, Context context){

		//		pushChatMember = pushChatMemberParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatMemberController";
		methodName = "updateMemberInformationWithProfileImage";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;

		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httppost ;
		MultipartEntity mpEntity ;
		HttpResponse response = null;
		HttpEntity resEntity = null ;
		String callResult;
		try {
			httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
			httppost = new HttpPost(fullUrl);
			mpEntity = new MultipartEntity();
			//차후 수정 서버 부분 수정

			//			obj.put("memberId", pushChatMember.getMemberId());
			//			//			obj.put("password", pushChatMember.getPassword());
			//			obj.put("nickName", pushChatMember.getNickName());
			//			obj.put("phoneNumber", pushChatMember.getPhoneNumber());
			//			obj.put("email", pushChatMember.getEmail());
			//			obj.put("comment", pushChatMember.getComment());
			//			obj.put("profileImageUrl", pushChatMember.getProfileImageUrl());
			//			obj.put("thumbnailUrl", pushChatMember.getThumbnailUrl());			// * 추가된 사항
			//			obj.put("gender", pushChatMember.getGender());
			//			obj.put("age", pushChatMember.getAge());
			//			obj.put("countryCode", pushChatMember.getCountryCode());
			//			obj.put("languageCode", pushChatMember.getLanguageCode());
			mpEntity.addPart("memberId", new StringBody(pushChatMemberParam.getMemberId()));
			mpEntity.addPart("nickName", new StringBody(pushChatMemberParam.getNickName()));
			mpEntity.addPart("phoneNumber", new StringBody(pushChatMemberParam.getPhoneNumber()));
			mpEntity.addPart("email", new StringBody(pushChatMemberParam.getEmail()));
			mpEntity.addPart("comment", new StringBody(pushChatMemberParam.getComment()));
			mpEntity.addPart("profileImageUrl", new StringBody(pushChatMemberParam.getProfileImageUrl()));
			mpEntity.addPart("thumbnailUrl", new StringBody(pushChatMemberParam.getThumbnailUrl()));
			mpEntity.addPart("gender", new StringBody(pushChatMemberParam.getGender()));
			mpEntity.addPart("age", new StringBody(pushChatMemberParam.getAge()));
			mpEntity.addPart("countryCode", new StringBody(pushChatMemberParam.getCountryCode()));
			mpEntity.addPart("languageCode", new StringBody(pushChatMemberParam.getLanguageCode()));
			mpEntity.addPart("latitude", new StringBody(pushChatMemberParam.getLatitude()));
			mpEntity.addPart("longitude", new StringBody(pushChatMemberParam.getLongitude()));
			mpEntity.addPart("location", new StringBody(pushChatMemberParam.getLocation()));
			mpEntity.addPart("openLocationYn", new StringBody(pushChatMemberParam.getOpenLocationYn()));
			mpEntity.addPart("personalityType", new StringBody(pushChatMemberParam.getPersonalityType()));
			mpEntity.addPart("deviceType", new StringBody(pushChatMemberParam.getDeviceType()));
			mpEntity.addPart("registrationId", new StringBody(pushChatMemberParam.getRegistrationId()));
			mpEntity.addPart("receiveNotificationYn", new StringBody(pushChatMemberParam.getReceiveNotificationYn()));
			mpEntity.addPart("activateYn", new StringBody("Y"));
			mpEntity.addPart("modifyDate", new StringBody(nowDate));

			//			obj.put("latitude", pushChatMember.getLatitude());
			//			obj.put("longitude", pushChatMember.getLongitude());
			//			obj.put("location", pushChatMember.getLocation());
			//			obj.put("openLocationYn", pushChatMember.getOpenLocationYn());
			//			obj.put("personalityType", pushChatMember.getPersonalityType());
			//			obj.put("deviceType", pushChatMember.getDeviceType());
			//			obj.put("registrationId", pushChatMember.getRegistrationId());
			//			obj.put("receiveNotificationYn", pushChatMember.getReceiveNotificationYn());
			//			obj.put("activateYn", "Y");
			//			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
			//			obj.put("fileName", imageFile.getFileName()); 			
			//			obj.put("imageData", imageFile.getImageData());

			// 이미지가 있으면 이미지를 보냄
			Bitmap selectedImg = pushChatMemberParam.getProfileImage();

			//Convert bitmap to byte array
			ByteArrayOutputStream bos = new ByteArrayOutputStream();		// ByteArrayOutputStream 객체 bos 생성
			selectedImg.compress(Bitmap.CompressFormat.PNG, 0, bos);		// 이미지를 PNG로 변환하여 bos 에 저장
			byte[] data = bos.toByteArray();								// 이미지를 byte[] 형으로 꺼냄
			Log.d(TAG,"img size3:"+data.length);							// 파일 용량

			String fileName = pushChatMemberParam.getMemberId() + "_" + commonUtil.getNowDateForImage() + ".png";		// 이미지 이름 설정
			Log.d(TAG,"fileName::"+fileName);
			mpEntity.addPart("fileName", new StringBody(fileName));

			File file = new File(context.getCacheDir(), fileName);
			file.createNewFile();

			//write the bytes in file
			FileOutputStream fos = new FileOutputStream(file);
			fos.write(data);
			fos.flush();
			fos.close();

			// 이부분의 설정으로 파일을 보낸다.
			ContentBody cbFile = new FileBody(file, "image/jpeg");
			mpEntity.addPart("file", cbFile);  //서버에서 처리해주는 파일이름이 file 이 되겠고, 내가 보내는 파일이 cbFile이다.	
			// 문서상에는 imageData 라고 되어있는데 실제로는 순번 가맹점 이벤트 등록때처럼 file 이었음.
			//			mpEntity.addPart("imageData", cbFile);  //서버에서 처리해주는 파일이름이 imageData 이 되겠고, 내가 보내는 파일이 cbFile이다.
			//			}
			httppost.setEntity(mpEntity);
			response = httpclient.execute(httppost);
			resEntity = response.getEntity();
			httpclient.getConnectionManager().shutdown();

			if (resEntity != null) {
				String tmpStr = EntityUtils.toString(resEntity);
				Log.d(TAG,"tmpStr:"+tmpStr);
				try {
					jsonObject = new JSONObject(tmpStr);
					callResult = jsonObject.getString("result").toString(); 
				} catch (Exception e) {
					callResult = "F";
					e.printStackTrace();
				}
			}else{
				callResult = "F";
			}
		} catch (Exception e) {
			callResult = "F";
			e.printStackTrace();
		}
		return callResult;
	}

	/* -- 채팅 메시지 관련 -- */
	/**
	 * RestRegisterMessage
	 * 메시지를 등록 한다.
	 */
	public String RestRegisterMessage(PushChatMessage pushChatMessageParam){

		//		pushChatMessage = pushChatMessageParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatMessageController";
		methodName = "registerMessage";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("content", pushChatMessageParam.getContent());
			obj.put("fileUrl", "");
			obj.put("thumbnailUrl", "");
			obj.put("ip", pushChatMessageParam.getIp());

			obj.put("activateYn", "Y");
			obj.put("modifyDate", nowDate);
			obj.put("registerDate", nowDate);

			obj.put("pushChatChatIdChat", pushChatMessageParam.getPushChatChatIdChat());
			obj.put("pushChatChatOwner", pushChatMessageParam.getPushChatChatOwner());
			obj.put("pushChatUserIdUser", pushChatMessageParam.getPushChatUserIdUser());
			obj.put("pushChatUserMemberId", pushChatMessageParam.getPushChatUserMemberId());
			obj.put("pushChatUserPushChatChatIdChat", pushChatMessageParam.getPushChatUserPushChatChatIdChat());
			obj.put("pushChatUserPushChatChatOwner", pushChatMessageParam.getPushChatUserPushChatChatOwner());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);
		Log.d(TAG,"RestRegisterMessage callResult:"+callResult);
		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);
			//			callResult = tempstr;
			//			try {
			//				jsonObject = new JSONObject(tempstr);		// result
			//				callResult = "";
			//				try{
			//					callResult = jsonObject.getString("result");
			//				}catch(Exception e){
			//					callResult = "F";
			//				}
			//			} catch (JSONException e) {
			//				callResult = "F";
			//			}
		}
		return callResult;
	}

	/**
	 * RestRegisterMessageWithImage
	 * 메시지와 이미지를 등록 한다.
	 */
	public String RestRegisterMessageWithImage(PushChatMessage pushChatMessageParam, Context context){
		Log.d(TAG, "RestRegisterMessageWithImage");
		//		pushChatMessage = pushChatMessageParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatMessageController";
		methodName = "registerMessageWithImage";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;

		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httppost ;
		MultipartEntity mpEntity ;
		HttpResponse response = null;
		HttpEntity resEntity = null ;
		String callResult;

		try {
			httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
			httppost = new HttpPost(fullUrl);
			mpEntity = new MultipartEntity();
			//차후 수정 서버 부분 수정

			mpEntity.addPart("content", new StringBody(pushChatMessageParam.getContent()));
			mpEntity.addPart("fileUrl", new StringBody(""));
			mpEntity.addPart("thumbnailUrl", new StringBody(""));
			mpEntity.addPart("ip", new StringBody(pushChatMessageParam.getIp()));
			mpEntity.addPart("activateYn", new StringBody("Y"));
			mpEntity.addPart("modifyDate", new StringBody(nowDate));
			mpEntity.addPart("registerDate", new StringBody(nowDate));
			Log.d(TAG,"pushChatMessage.getPushChatChatIdChat():"+pushChatMessageParam.getPushChatChatIdChat());
			mpEntity.addPart("pushChatChatIdChat", new StringBody(pushChatMessageParam.getPushChatChatIdChat()));
			mpEntity.addPart("pushChatChatOwner", new StringBody(pushChatMessageParam.getPushChatChatOwner()));
			mpEntity.addPart("pushChatUserIdUser", new StringBody(pushChatMessageParam.getPushChatUserIdUser()));
			mpEntity.addPart("pushChatUserMemberId", new StringBody(pushChatMessageParam.getPushChatUserMemberId()));
			mpEntity.addPart("pushChatUserPushChatChatIdChat", new StringBody(pushChatMessageParam.getPushChatUserPushChatChatIdChat()));
			mpEntity.addPart("pushChatUserPushChatChatOwner", new StringBody(pushChatMessageParam.getPushChatUserPushChatChatOwner()));

			// 이미지가 있으면 이미지를 보냄
			Bitmap selectedImg = pushChatMessageParam.getUploadFileImg();

			//Convert bitmap to byte array
			ByteArrayOutputStream bos = new ByteArrayOutputStream();		// ByteArrayOutputStream 객체 bos 생성
			selectedImg.compress(Bitmap.CompressFormat.PNG, 0, bos);		// 이미지를 PNG로 변환하여 bos 에 저장
			byte[] data = bos.toByteArray();								// 이미지를 byte[] 형으로 꺼냄
			Log.d(TAG,"img size3:"+data.length);							// 파일 용량

			String fileName = pushChatMessageParam.getPushChatUserMemberId() + "_" + commonUtil.getNowDateForImage() + ".png";		// 이미지 이름 설정
			Log.d(TAG,"fileName::"+fileName);
			mpEntity.addPart("fileName", new StringBody(fileName));

			File file = new File(context.getCacheDir(), fileName);
			file.createNewFile();

			//write the bytes in file
			FileOutputStream fos = new FileOutputStream(file);
			fos.write(data);
			fos.flush();
			fos.close();

			// 이부분의 설정으로 파일을 보낸다.
			ContentBody cbFile = new FileBody(file, "image/jpeg");
			mpEntity.addPart("file", cbFile);  //서버에서 처리해주는 파일이름이 file 이 되겠고, 내가 보내는 파일이 cbFile이다.	
			// 문서상에는 imageData 라고 되어있는데 실제로는 순번 가맹점 이벤트 등록때처럼 file 이었음.
			//			mpEntity.addPart("imageData", cbFile);  //서버에서 처리해주는 파일이름이 imageData 이 되겠고, 내가 보내는 파일이 cbFile이다.
			//			}
			httppost.setEntity(mpEntity);
			response = httpclient.execute(httppost);
			resEntity = response.getEntity();
			if (resEntity != null) {
				String tmpStr = EntityUtils.toString(resEntity);

				callResult = tmpStr;

				//				try {
				//					jsonObject = new JSONObject(tmpStr);
				//					callResult = jsonObject.getString("result").toString(); 
				//				} catch (Exception e) {
				//					callResult = "F";
				//					e.printStackTrace();
				//				}
			}else{
				callResult = "F";
			}
			httpclient.getConnectionManager().shutdown();
		} catch (Exception e) {
			callResult = "F";
			e.printStackTrace();
		}
		return callResult;
	}

	/**
	 * RestSelectMessageList
	 * 메시지 목록을 가져 온다.
	 */
	public String RestSelectMessageList(PushChatMessage pushChatMessageParam){

		//		pushChatMessage = pushChatMessageParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatMessageController";
		methodName = "selectMessageList";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("activateYn", "Y");
			//			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
			obj.put("pushChatChatIdChat", pushChatMessageParam.getPushChatChatIdChat());
			//			obj.put("pushChatChatOwner", pushChatMessage.getPushChatChatOwner());
			//			obj.put("pushChatUserIdUser", pushChatMessage.getPushChatUserIdUser());
			//			obj.put("pushChatUserMemberId", pushChatMessage.getPushChatUserMemberId());
			//			obj.put("pushChatUserPushChatChatIdChat", pushChatMessage.getPushChatUserPushChatChatIdChat());
			//			obj.put("pushChatUserPushChatChatOwner", pushChatMessage.getPushChatUserPushChatChatOwner());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			// 코드에서 처리
			// callResult = tempstr;
		}
		return callResult;
	}

	/* -- 채팅 글 확인 읽음 여부 관련 -- */	
	/**
	 * RestRegisterRecognition
	 * 사용자를 인지 테이블에 등록 한다.
	 */
	public String RestRegisterRecognition(PushChatRecognition pushChatRecognitionParam){

		//		pushChatRecognition = pushChatRecognitionParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatRecognitionController";
		methodName = "registerRecognition";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("memberId", pushChatRecognitionParam.getMemberId());
			obj.put("readYn", pushChatRecognitionParam.getReadYn());
			obj.put("activateYn", "Y");
			obj.put("modifyDate", nowDate);
			obj.put("registerDate", nowDate);
			obj.put("pushChatChatIdChat", pushChatRecognitionParam.getPushChatChatIdChat());
			obj.put("pushChatChatOwner", pushChatRecognitionParam.getPushChatChatOwner());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);
			try {
				jsonObject = new JSONObject(callResult);		// result
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		return callResult;
	}

	/**
	 * RestSelectDuplicationRecognition
	 * 사용자가 인지 테이블에 등록되어 있는지 중복 확인한다.
	 */
	public String RestSelectDuplicationRecognition(PushChatRecognition pushChatRecognitionParam){

		//		pushChatRecognition = pushChatRecognitionParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatRecognitionController";
		methodName = "selectDuplicationRecognition";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("memberId", pushChatRecognitionParam.getMemberId());
			//			obj.put("readYn", pushChatRecognition.getReadYn());
			obj.put("activateYn", "Y");
			//			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
			obj.put("pushChatChatIdChat", pushChatRecognitionParam.getPushChatChatIdChat());
			obj.put("pushChatChatOwner", pushChatRecognitionParam.getPushChatChatOwner());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){

			//			Log.d(TAG,"tempstr:"+tempstr);

			// callResult = tempstr;
			//			try {
			//				jsonObject = new JSONObject(tempstr);		// totalCount
			//				try{
			//					callResult = jsonObject.getString("totalCount");
			//				}catch(Exception e){
			//					callResult = "F";
			//				}
			//			} catch (JSONException e) {
			//				callResult = "F";
			//			}
		}else{
			callResult = "F";
		}
		return callResult;
	}

	/**
	 * RestUpdateReadYn
	 * 인지 테이블의 메시지 읽음 여부를 업데이트 한다.
	 */
	public String RestUpdateReadYn(PushChatRecognition pushChatRecognitionParam){

		//		pushChatRecognition = pushChatRecognitionParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatRecognitionController";
		methodName = "updateReadYn";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("memberId", pushChatRecognitionParam.getMemberId());
			obj.put("readYn", pushChatRecognitionParam.getReadYn());
			obj.put("activateYn", "Y");
			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
			obj.put("pushChatChatIdChat", pushChatRecognitionParam.getPushChatChatIdChat());
			obj.put("pushChatChatOwner", pushChatRecognitionParam.getPushChatChatOwner());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);

			// callResult = tempstr;
			//			try {
			//				jsonObject = new JSONObject(tempstr);		// result
			//				try{
			//					callResult = jsonObject.getString("result");
			//				}catch(Exception e){
			//					callResult = "F";
			//				}
			//			} catch (JSONException e) {
			//				callResult = "F";
			//			}
		}
		return callResult;
	}

	/**
	 * RestSelectRecognitionInformation
	 * 인지 테이블의 사용자 정보를 가져 온다.
	 */
	public String RestSelectRecognitionInformation(PushChatRecognition pushChatRecognitionParam){

		//		pushChatRecognition = pushChatRecognitionParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatRecognitionController";
		methodName = "selectRecognitionInformation";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("memberId", pushChatRecognitionParam.getMemberId());
			//			obj.put("readYn", pushChatRecognition.getReadYn());
			obj.put("activateYn", "Y");
			//			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
			obj.put("pushChatChatIdChat", pushChatRecognitionParam.getPushChatChatIdChat());
			obj.put("pushChatChatOwner", pushChatRecognitionParam.getPushChatChatOwner());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);
			//			try {
			//				jsonObject = new JSONObject(tempstr);
			//				callResult = "";
			//				try{
			//					callResult = jsonObject.getString("totalCount");
			//				}catch(Exception e){
			//					callResult = "0";
			//				}
			//			} catch (JSONException e) {
			//				callResult = "0";
			//			}
		}
		return callResult;
	}
	/**
	 * RestSelectRecognitionList
	 * 인지 테이블의 사용자 목록을 가져 온다.
	 */
	public String RestSelectRecognitionList(PushChatRecognition pushChatRecognitionParam){

		//		pushChatRecognition = pushChatRecognitionParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatRecognitionController";
		methodName = "selectRecognitionList";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			//			obj.put("memberId", pushChatRecognition.getMemberId());
			//			obj.put("readYn", pushChatRecognition.getReadYn());
			obj.put("activateYn", "Y");
			//			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
			obj.put("pushChatChatIdChat", pushChatRecognitionParam.getPushChatChatIdChat());
			obj.put("pushChatChatOwner", pushChatRecognitionParam.getPushChatChatOwner());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);
			//			try {
			//				jsonObject = new JSONObject(tempstr);		// list
			//				callResult = "";
			//				try{
			//					callResult = jsonObject.getString("totalCount");
			//				}catch(Exception e){
			//					callResult = "0";
			//				}
			//			} catch (JSONException e) {
			//				callResult = "0";
			//			}
		}
		return callResult;
	}


	/* -- 추천(좋아요) 관련 -- */
	/**
	 * RestSelectDuplicationRecommendation
	 * 추천 등록 시 중복 여부를 확인 한다.
	 */
	public String RestSelectDuplicationRecommendation(PushChatRecommendation pushChatRecommendationParam){

		//		pushChatRecommendation = pushChatRecommendationParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatRecommendationController";
		methodName = "selectDuplicationRecommendation";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("memberId", pushChatRecommendationParam.getMemberId());
			obj.put("activateYn", "Y");
			obj.put("pushChatDiaryIdPushChatDiary", pushChatRecommendationParam.getPushChatDiaryIdPushChatDiary());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){

			try {
				jsonObject = new JSONObject(callResult);		// totalCount			
				try{
					callResult = jsonObject.getString("totalCount");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}		// 0 , n , F
		}
		Log.d(TAG,"callResult:"+callResult);
		return callResult;
	}
	/**
	 * RestRegisterRecommendation
	 * 추천을 등록 한다.
	 */
	public String RestRegisterRecommendation(PushChatRecommendation pushChatRecommendationParam){

		//		pushChatRecommendation = pushChatRecommendationParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatRecommendationController";
		methodName = "registerRecommendation";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("memberId", pushChatRecommendationParam.getMemberId());
			obj.put("evaluation", pushChatRecommendationParam.getEvaluation());
			obj.put("content", pushChatRecommendationParam.getContent());
			obj.put("activateYn", "Y");
			obj.put("modifyDate", nowDate);
			obj.put("registerDate", nowDate);
			obj.put("pushChatDiaryIdPushChatDiary", pushChatRecommendationParam.getPushChatDiaryIdPushChatDiary());
			obj.put("pushChatDiaryMemberId", pushChatRecommendationParam.getPushChatDiaryMemberId());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);
			try {
				jsonObject = new JSONObject(callResult);		// result
				callResult = "";
				try{
					callResult = jsonObject.getString("result");
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		return callResult;
	}


	/* -- 채팅방 사용자 관련 -- */
	/**
	 * RestRegisterUser
	 * 채팅방에 사용자를 등록 한다.
	 */
	public String RestRegisterUser(PushChatUser pushChatUserParam){

		//		pushChatUser = pushChatUserParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatUserController";
		methodName = "registerUser";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("memberId", pushChatUserParam.getMemberId());
			obj.put("activateYn", "Y");
			obj.put("modifyDate", nowDate);
			obj.put("registerDate", nowDate);
			obj.put("pushChatChatIdChat", pushChatUserParam.getPushChatChatIdChat());
			obj.put("pushChatChatOwner", pushChatUserParam.getPushChatChatOwner());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			try {
				jsonObject = new JSONObject(callResult);		// result
				try{
					callResult = jsonObject.getString("result");
					if(callResult.equals("FAIL")){
						callResult = "F";
					}
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		return callResult;
	}
	/**
	 * RestSelectUserInformation
	 * 채팅 사용자 정보를 가져 온다.
	 */
	public String RestSelectUserInformation(PushChatUser pushChatUserParam){

		//		pushChatUser = pushChatUserParam;

		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		// 파라미터 셋팅
		controllerName = "pushChatUserController";
		methodName = "selectUserInformation";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			obj.put("memberId", pushChatUserParam.getMemberId());
			obj.put("activateYn", "Y");
			//			obj.put("modifyDate", nowDate);
			//			obj.put("registerDate", nowDate);
			obj.put("pushChatChatIdChat", pushChatUserParam.getPushChatChatIdChat());
			obj.put("pushChatChatOwner", pushChatUserParam.getPushChatChatOwner());
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			//			Log.d(TAG,"tempstr:"+tempstr);

			// callResult = tempstr;
			//			try {
			//				jsonObject = new JSONObject(tempstr);		// user
			//				/*
			//				 * "idUser":"140",	"memberId":"test05",
			//				 * "pushChatChatIdChat":"89","pushChatChatOwner":"test01",
			//				 * "totalCount":null,"result":null,"deviceType":"AS","registrationId":"APA91bHAE8sJhvJKGG_vV60eY4I5qVwfO4GJAo4gME5oZ_9eKa_L9m7p3ppfso1H7ANbByRjJfkxUauYl9X2QVX3tFuhamdn0HunJLO7FN86rCeXC_ymxqc1Ia_g5Ay8gK-293LQRGf8YFZ0ovYtswtjivpxt3e_31pOKO_q6JCrLPfEGgiUSco"}
			//				 */
			//				//				callResult = "";
			//				try{
			//					pushChatUser.setIdUser(jsonObject.getString("idUser"));
			//					pushChatUser.setMemberId(jsonObject.getString("memberId"));
			//					pushChatUser.setPushChatChatIdChat(jsonObject.getString("pushChatChatIdChat"));
			//					pushChatUser.setPushChatChatOwner(jsonObject.getString("pushChatChatOwner"));
			//				}catch(Exception e){
			//					callResult = "F";
			//				}
			//			} catch (JSONException e) {
			//				callResult = "F";
			//			}
		}
		return callResult;
	}


	/**
	 * RestRegisterBlock		registerBlock	// SUCCESS / F
	 * 채팅 사용자 차단(신고)
	 */
	public String RestRegisterBlock(PushChatBlock pushChatBlockParam){
		CommonUtil commonUtil = new CommonUtil();
		nowDate = commonUtil.getNowDate();

		/*
		 * 1. 먼저 중복 체크를 한다.
		 */
		// 파라미터 셋팅
		controllerName = "pushChatBlockController";
		methodName = "selectDuplicationBlock";
		fullUrl = serverName+"/"+controllerName+"/"+methodName;
		obj = new JSONObject();
		try{		
			/*
			memberId
			idChat
			idPushChatDiary
			reporter
			activateYn
			 */
			obj.put("memberId", pushChatBlockParam.getMemberId());
			obj.put("idChat", pushChatBlockParam.getIdChat());
			obj.put("idPushChatDiary", pushChatBlockParam.getIdPushChatDiary());
			obj.put("reporter", pushChatBlockParam.getReporter());
			obj.put("activateYn", "Y");
		}catch(Exception e){
			e.printStackTrace();
		}
		inputJson = obj.toString();

		// 서버호출 메소드 실행
		String callResult = callServerMethod(fullUrl, inputJson);

		// 서버 호출 결과 처리
		if(!(callResult.equals("F"))){
			Log.d(TAG,"callResult:"+callResult);
			try {
				jsonObject = new JSONObject(callResult);		// result SUCCESS		PushChatBlock.totalCount
				try{
					callResult = jsonObject.getString("totalCount");
					if(!callResult.equals("0")){
						callResult = "D";		// 중복
					}
				}catch(Exception e){
					callResult = "F";
				}
			} catch (JSONException e) {
				callResult = "F";
			}
		}
		
		if(callResult.equals("0")){
			/*
			 * 2. 사용자를 차단(신고)한다.
			 */
			// 파라미터 셋팅
			controllerName = "pushChatBlockController";
			methodName = "registerBlock";
			fullUrl = serverName+"/"+controllerName+"/"+methodName;
			obj = new JSONObject();
			try{		
				/*
				 * memberId : 차단(신고)할 상대방 아이디.	!!
					idChat(옵션) : 채팅방 아이디.					!
					idPushChatDiary(옵션) : 다이어리 아이디.		!
					reason(옵션) : 공백							""
					reporter : 신고자 아이디.						!!
					activateYn : Y
					modifyDate : 현재 날짜.
					registerDate : 현재 날짜.
				 */
				obj.put("memberId", pushChatBlockParam.getMemberId());
				obj.put("idChat", pushChatBlockParam.getIdChat());
				obj.put("idPushChatDiary", pushChatBlockParam.getIdPushChatDiary());
				obj.put("reason", pushChatBlockParam.getReason());
				obj.put("reporter", pushChatBlockParam.getReporter());
				obj.put("activateYn", "Y");
				obj.put("modifyDate", nowDate);
				obj.put("registerDate", nowDate);
			}catch(Exception e){
				e.printStackTrace();
			}
			inputJson = obj.toString();

			// 서버호출 메소드 실행
			callResult = callServerMethod(fullUrl, inputJson);

			// 서버 호출 결과 처리
			if(!(callResult.equals("F"))){
				Log.d(TAG,"callResult:"+callResult);
				if(!(callResult.equals("F"))){
					try {
						jsonObject = new JSONObject(callResult);		// result SUCCESS
						try{
							callResult = jsonObject.getString("result");
							if(callResult.equals("FAIL")){
								callResult = "F";
							}
						}catch(Exception e){
							callResult = "F";
						}
					} catch (JSONException e) {
						callResult = "F";
					}
				}
			}
		}
		
		return callResult;
	}
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	// 이미지 처리
	/**
	 * LoadImage
	 *  이미지 URL 에서 이미지 받아온 스트림을 비트맵으로 저장한다
	 *
	 * @param $imagePath
	 * @param
	 * @return bm
	 */
	private Bitmap LoadImage( String $imagePath ) {
		InputStream inputStream = OpenHttpConnection( $imagePath ) ;
		Bitmap bm = BitmapFactory.decodeStream( inputStream ) ;
		return bm;
	}
	/**
	 * OpenHttpConnection
	 *  이미지 URL 에서 이미지 받아와서 스트림으로 저장한다
	 *
	 * @param $imagePath
	 * @param
	 * @return stream
	 */
	private InputStream OpenHttpConnection(String $imagePath) {
		// TODO Auto-generated method stub
		InputStream stream = null ;
		try {
			URL url = new URL( $imagePath ) ;
			HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection() ;
			urlConnection.setRequestMethod( "GET" ) ;
			urlConnection.connect() ;
			if( urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK ) {
				stream = urlConnection.getInputStream() ;
			}
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			Log.d(TAG,"OpenHttpConnection-"+$imagePath);
			Log.w(TAG,"MalformedURLException");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			Log.w(TAG,"IOException");
		}
		return stream ;
	}


	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	// 공용 서버 호출 메소드
	public String callServerMethod(String fullUrl, String inputJson){
		String callResult;
		try{
			URL postUrl2 = new URL(fullUrl);
			HttpURLConnection connection2 = (HttpURLConnection) postUrl2.openConnection();
			connection2.setConnectTimeout(CommonConstant.serverConnectTimeOut);
			connection2.setDoOutput(true);
			connection2.setInstanceFollowRedirects(false);
			connection2.setRequestMethod("POST");
			connection2.setRequestProperty("Content-Type", "application/json");
			Thread.sleep(200);
			OutputStream os2 = connection2.getOutputStream();
			os2.write(inputJson.getBytes("UTF-8"));
			os2.flush();
			responseCode = connection2.getResponseCode();
			InputStream in =  connection2.getInputStream();
			if(responseCode==200 || responseCode==204){
				// 결과를 처리.
				BufferedReader reader = new BufferedReader(new InputStreamReader(in), 8192);
				StringBuilder builder = new StringBuilder();
				String line =null;
				try {
					while((line=reader.readLine())!=null){
						builder.append(line).append("\n");
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
				//				tempstr = builder.toString();
				//				callResult = "S";
				callResult = builder.toString();
			}else{
				Log.d(TAG,"Fail["+responseCode+"]");
				callResult="F";
			}
		}catch(Exception e){ 
			e.printStackTrace();
			callResult="F";
			//			initNetwork();
		}
		isRunning = 0;
		return callResult;
	}

	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
	// 유틸

}
